# -*- coding = utf-8 -*-
# @Time : 2021/12/1 17:53
# @Author : chenxingjia
# @File : test.py


n, v = map(int, input().split(' '))
goods = []
for i in range(n):
    goods.append([int(i) for i in input().split()])
dp = [0 for i in range(v+1)]
for i in range(n):
    for j in range(v,-1,-1): # 从后往前
        k = j//goods[i][0]  # 能选多少次
        # 从这些次里面取最大
        dp[j] = max([dp[j-x* goods[i][0]] + x * goods[i][1] for x in range(k+1)])

print(dp[-1])